home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / music / kardp11.zip / KARAFM.C < prev    next >
C/C++ Source or Header  |  1994-12-23  |  4KB  |  160 lines

  1. /*
  2.      KARAOKE
  3.  
  4.      Copyright (c) 1993 94 JP COCATRIX . All rights reserved.
  5. */
  6. /*  This is the interface module used in karados
  7.         given as an explaination of how the resident code like Ultramid
  8.         is used.
  9.         These primitives are called only if the output mode is s (-po=s)
  10.         I Hope it is self documented.
  11.         If loading a patches is no meaning for you, just ignore in the TSR
  12.         The APP_START and APP_END is only a protection for multiple users
  13.         to avoid the remove of the TSR if a program is still using it.
  14.         The key for detection for an other TSR than ULTRAMID
  15.         is KARADOS. Dont use ULTRAMID
  16. */
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include <dos.h>
  20.  
  21. #define TSR_LOAD_PATCH                12
  22. #define TSR_UNLOAD_ALL_PATCHES      15
  23. #define TSR_MIDI_OUT                  16
  24. #define TSR_ALL_NOTES_OFF            18
  25. #define TSR_APP_START                  26
  26. #define TSR_APP_END                    27
  27. #define control_change              0xb0
  28.  
  29. extern enum HARD {RIEN,SB,GUS} hardware;
  30. extern void SaySo(char *texte,int multiple);
  31. extern short inrange(unsigned char,unsigned char min,unsigned char max);
  32. extern const char *getInstrument(unsigned char);
  33. void    sbFmSound(int );
  34. //*******************************************************************
  35. //                 code Synth. output
  36. //*******************************************************************
  37.  
  38. void (far *um_hook)(void) = 0L;
  39.  
  40.  
  41. void    um_parameter( int channel, int control, int value )
  42. {
  43.     sbFmSound( (control_change+channel) );
  44.     sbFmSound( control );
  45.     sbFmSound( value );
  46. }
  47.  
  48. void    loadpatch( int patch )
  49. {
  50.     char strg[80];
  51.     if (um_hook)
  52.     {
  53.         if (patch <128)
  54.         sprintf(strg,"Loading %s",getInstrument(patch));
  55.         else
  56.         {
  57.             if (!inrange(patch,128+27,128+87)) return;
  58.             sprintf(strg,"Loading drum %d",patch-128);
  59.         }
  60.         SaySo(strg,6);
  61.         _AX = TSR_LOAD_PATCH;
  62.         _CX = patch;
  63.         (*um_hook)();
  64.     }
  65. }
  66.  
  67.  
  68. int    reset_um( )
  69. {
  70.     int i;
  71.  
  72.     _AX = TSR_ALL_NOTES_OFF;
  73.     if (um_hook) (*um_hook)();
  74.     for (i=0; i < 16; i++) {
  75.         um_parameter(i, 0x78, 0); /* all sounds off */
  76.         um_parameter(i, 0x79, 0); /* reset all controllers */
  77.         um_parameter(i, 100, 0); /* RPN MSB 0 */
  78.         um_parameter(i, 101, 0); /* RPN LSB 0 */
  79.         um_parameter(i, 6, 2); /* Pitch Bend Sensitivity MSB */
  80.         um_parameter(i, 38, 0); /* Pitch Bend Sensitivity LSB */
  81.     }
  82.     return(1);
  83. }
  84.  
  85. void    um_cleanup( void )
  86. {
  87.     reset_um();
  88.     if (um_hook)
  89.     {
  90.         SaySo("Unload Patches",6);
  91.         _AX = TSR_UNLOAD_ALL_PATCHES;
  92.         (*um_hook)();
  93.         _AX = TSR_APP_END;
  94.         (*um_hook)();
  95.     }
  96. }
  97.  
  98.  
  99. //***********************************************************************
  100. //                code commun   common code
  101. //***********************************************************************
  102. // name with FM are for historical reasons !!
  103. #pragma warn -par
  104. int    initfm()
  105. {
  106.     int vector, i;
  107.     char far *stamp;
  108.  
  109.     switch (hardware)
  110.     {
  111.     case GUS:
  112.     case SB:
  113.         for (vector=0x78; vector <= 0x7f; vector++)
  114.         {
  115.             um_hook = (void (far *)())getvect(vector);
  116.             stamp = (char far *)MK_FP( FP_SEG(um_hook), 0x103 );
  117.             if ((strncmp(stamp, "ULTRAMID", 8) == 0)||(strncmp(stamp, "KARADOS", 7) == 0)) break;
  118.         }
  119.         if (vector <= 0x7f) {
  120.             if (um_hook)
  121.             {
  122.                 _AX = TSR_APP_START;
  123.                 (*um_hook)();
  124.                 _AX = TSR_UNLOAD_ALL_PATCHES;
  125.                 (*um_hook)();
  126.                 reset_um();
  127.             }
  128.         } else
  129.         {
  130.             um_hook = 0L;
  131.             return(1);
  132.         }
  133.         return(0);
  134.     case RIEN :
  135.     default:
  136.         printf (" No synth. Sorry.\n");
  137.         return (1);
  138.     }
  139. }
  140. #pragma warn .par
  141.  
  142.  
  143. void    sbFmSound(int car )
  144. {
  145.     switch (hardware)
  146.     {
  147.     case GUS:
  148.     case SB:
  149.         if (um_hook)
  150.         {
  151.             _AX = TSR_MIDI_OUT;
  152.             _CX = car;
  153.             (*um_hook)();
  154.         }
  155.         break;
  156.     default:break;
  157.     }
  158. }
  159.  
  160.